<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/**
 * Description of banner_model
 * 
 * @author Subha Sundar Das (subhasundar.das@gmail.com)
 */
class Reviews_model extends CI_Model {

    //put your code here
    //--Subha (Get Recent News with parameter no of News )--//    
    function get_recent_reviews($no) {
        if ($no) {
            $sql = "Select * from review_master where status=51 order by id desc limit $no ";
            return $this->db->query($sql)->result();
        }
    }

//--REVIEW RATING (Subha)--------//
    function review_ratting($model, $feature) {
        $experience = '0';
        $rate = 0;
        $sql = "SELECT $feature,COUNT(*) as 'no' FROM review_master WHERE model = $model GROUP BY $feature";
        $query = $this->db->query($sql);
        $result = $query->result();
        foreach ($result as $rating):

            if ($rating->no > $rate) {
                $rate = $rating->no;
                $experience = $rating->$feature;
            }
        endforeach;
        return $experience;
    }

    //-------- Get all reviews-----------------(Joydev)
    function get_reviews($status = NULL, $no = NULL, $offset = NULL) {
        if (isset($status)) {
            $sql = "select * from review_master where status=$status order by posted_on desc limit $offset, $no";
        } else {
            $sql = "select * from review_master limit $offset, $no";
        }
        $query = $this->db->query($sql);
        if ($query) {
            $result = $query->result();
            return $result;
        } 
    }

//----------- Change Status of review-------------(Joydev)
    function change_status($id, $status) {
        if ($status == 1) {
            $sql = "update review_master set status=51 where id=$id";
        }
        if ($status == 51) {
            $sql = "update review_master set status=1 where id=$id";
        }
        $this->db->query($sql);
    }

}

?>
